package com.ipartek.formacion.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class ParseURL {
	public static void main(String[] args) {
		URL aURL = null;
		try {
			aURL = new URL("http://www.google.com");
			System.out.println("protocol = " + aURL.getProtocol());
			System.out.println("host = " + aURL.getHost());
			System.out.println("filename = " + aURL.getFile());
			System.out.println("port = " + aURL.getPort());
			System.out.println("ref = " + aURL.getRef());
			System.out.println("-------------------------------");

			try {
				URLConnection con = aURL.openConnection();
				BufferedReader dis = new BufferedReader(new InputStreamReader(
						con.getInputStream()));
				String inputLine;

				while ((inputLine = dis.readLine()) != null) {
					System.out.println(inputLine);
				}
				dis.close();
			} catch (MalformedURLException me) {
				System.out.println("MalformedURLException: " + me);
			} catch (IOException ioe) {
				System.out.println("IOException: " + ioe);
			}
		} catch (MalformedURLException e) {
			System.out.println("MalformedURLException: " + e);
		}
	}
}